class Solution {
public:
    ListNode* reverseBetween(ListNode* head, int left, int right) {
        vector<int> nums;
        ListNode* L=head;
        for(int i=0;i<right;i++){//把需要转换的链表段提取出来
            if(i>=left-1){
                nums.push_back(L->val);
                L=L->next;
            }
            else{
                L=L->next;
            }
        }
        int temp = 0;
        for(int j=0;j<nums.size()/2;j++){//翻转数组
            temp = nums[j];
            nums[j] = nums[nums.size()-1-j];
            nums[nums.size()-1-j] = temp;
        }
        int k = 0;
        L = head;
        for(int i=0;i<right;i++){//放回原链表
            if(i>=left-1){
                L->val=nums[k];
                k++;
                L=L->next;
            }
            else{
                L=L->next;
            }
        }
        return head;
    }
};
